﻿using System;
using System.Reflection;
using System.Data;
using CookstaFramework.Objects;
using System.Collections.Generic;
namespace CookstaFramework.Data
{
	public static class DataTools
	{
		private static RecordCollection<T> DatatableReader<T>(DataTable dt) where T : RecordBase, new()
        {
            RecordCollection<T> results = new RecordCollection<T>();
            List<PropertyInfo> properties = new List<PropertyInfo>(typeof(T).GetProperties());
            T temp;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                temp = new T();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    properties.Find(delegate(PropertyInfo pi)
                    {
                        return pi.Name == dt.Columns[j].ColumnName;
                    }).SetValue(temp, dt.Rows[i][j], null);
                }
                results.Add(temp);
            }
            return results;
        }
		
		
	}
}
